package com.xx.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xx.entity.User;
import com.xx.service.UserService;
import org.apache.struts2.interceptor.SessionAware;

import java.util.Map;

/*用户的Action*/
public class UserAction extends ActionSupport implements ModelDriven<User>,SessionAware{

    private User user = null;
    private Map<String,Object> session = null;
    private UserService userService = null;

    public User getModel() {
        user = new User();
        return this.user;
    }

    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

    /*进入登入界面的action*/
    public String loginView(){
        return this.LOGIN;
    }

    /*登入的action*/
    public String login(){
        userService = new UserService();
        if(userService.login(user)){
            session.put("user",user);
            return this.SUCCESS;
        }else{
            return this.ERROR;
        }
    }
}
